#include<iostream>
#include<cstdio>
#include<map>
#include<string>
using namespace std;
long long n,x,ans,a1,a2,a3,a4,a5;
map<string,long long> mps;
string s,ss;
char a,b,c,d;
int main(){
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		cin>>s;
		cin>>a1>>a>>a2>>b>>a3>>c>>a4>>d>>a5;
		if(a1<0||a1>255||a2<0||a2>255||a3<0||a3>255||a4<0||a4>255||a5<0||a5>65535||a!='.'||b!='.'||c!='.'||d!=':'){
			printf("ERR\n");
			continue;
		}
		ss=(a1+'0')+a+(a2+'0')+b+(a3+'0')+c+(a4+'0')+d+(a5+'0');
		if(s=="Server"){
			ans++;
			if(mps[ss]!=0)printf("FAIL\n");
			else{
				mps[ss]=ans;
				printf("OK\n");
			}
		}else{
			if(mps[ss]!=0)cout<<mps[ss]<<endl;
			else printf("FAIL\n");
		}
	}
}
